#include <iostream>
#include <exception>

using namespace std;

void catch_exc(){
    try
    {
        throw "Division by zero condition!";
    }
    catch (const char* msg) {
        cerr << msg << endl;
    }

    try
    {
        /* code */
    }
    catch(const std::exception& e)
    {
        std::cerr << e.what() << '\n';
    }
       
}

// 自定义异常
struct MyException : public exception
{
  const char * what () const throw ()
  {
    return "C++ Exception";
  }
};


int main(){
    try
    {
        throw MyException();
    }
    catch(MyException& e)
    {
        std::cout << "MyException caught" << std::endl;
        std::cout << e.what() << std::endl;
    }
    catch(std::exception& e)
    {
        //其他的错误
    }
}